package com.yxuan.springboot.controller;

import com.yxuan.springboot.model.EnrollmentPlan;
import com.yxuan.springboot.service.EnrollmentPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 
 * @author zchao
 *   EnrollmentPlan控制器
 * @date 2023-06-06 13:29:25
 */
@Controller
@Api(tags = "招生计划")
@RequestMapping(value = "/enrollmentplan", method = {RequestMethod.POST,RequestMethod.GET})
@CacheConfig(cacheNames = "enrollmentplan")//缓存名，和管理器中配置的一致
public class EnrollmentPlanController extends BaseController<EnrollmentPlan>{

    @Autowired
    private EnrollmentPlanService enrollmentPlanService;


    //根据条件（无条件）查询多个结果
    @ApiOperation(value = "根据条件（无条件）--查询多个结果---", notes = "根据条件（无条件）--查询多个结果--",httpMethod = "GET")
    @RequestMapping("/loadManyByPramas")
    @ResponseBody
//    @Cacheable(key = "'loadManyByPramas-' + #t",unless = "#result==null", condition = "#t!=null")//#result返回结果
    public List<EnrollmentPlan> loadManyByPramas(EnrollmentPlan t) {
        try {
            return enrollmentPlanService.findManyByPramas(t);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     *  查询对应省份院校的招生年份分组
     */
    @ApiOperation(value = "查询对应省份院校的招生年份分组", notes = "查询对应省份院校的招生年份分组")
    @RequestMapping("/loadYearByGroup")
    @ResponseBody
    @Cacheable(key = "'loadYearByGroup-' + #schoolId +#provinceName ",unless = "#result==null", condition = "#schoolId!=null && #provinceName!=null")//#result返回结果
    public List loadYearByGroup(String schoolId, String provinceName){
        return enrollmentPlanService.findYearByGroup(schoolId,provinceName);
    }


}
